package com.xs.daoimpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.xs.bean.VideoTableBean;
import com.xs.dao.VideoDao;
import com.xs.util.JdbcUtil;

public class VideoDaoImpl extends JdbcUtil implements VideoDao {

	// 获得video_user_id,即该老师菜单下的所有信息
	@Override
	public List getVideoInfoByUserId(int videoUserId) {
		//这里的video_user_id与user_id是对应的
		String sql = "select * from video_tb where video_user_id = " + videoUserId;
		ResultSet rs = this.query(sql);
		List list = new ArrayList();
		try {
			while (rs.next()) {
				VideoTableBean vtb = new VideoTableBean(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4),
						rs.getString(5), rs.getString(6), rs.getInt(7), rs.getInt(8));
				list.add(vtb);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	// 获得video
	@Override
	public VideoTableBean getVideoInfoById(int videoId) {
		String sql = "select *  from  video_tb where video_id = " + videoId;
		ResultSet rs = this.query(sql);
		VideoTableBean vtb = null;
		try {
			while (rs.next()) {
				vtb = new VideoTableBean(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4),
						rs.getString(5), rs.getString(6), rs.getInt(7), rs.getInt(8));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return vtb;
	}

	
	//添加上传的视频到sql里面
	@Override
	public boolean uploadVideo(VideoTableBean vb) {
		String sql="insert into  video_tb  value(0,?,?,?,?,?,?,?)";
		String[]  param= {vb.getVideoName(),vb.getVideoImgUrl(),vb.getVideoUrl(),vb.getVideoMsg(),vb.getVideoUploadTime()+"",vb.getVideoUserId()+"",vb.getVideoMajorId()+""};
		return this.update2(sql, param);
	}

	
}
